package com.gxa.controller.GlmController;

import com.gxa.entity.User;
import com.gxa.service.RerecordService;
import com.gxa.utils.R;
import com.gxa.vo.*;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "充值记录模块")
@RestController
public class RerecordController {

    @Autowired
    private RerecordService rerecordService;

    //门诊消费记录

    @ApiOperation(value="门诊充值记录渲染接口",notes="用于点击门诊充值记录时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊消费充值的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/rerecord/queryOutpatient")
    public R queryOutpatient(){
        List<OutrerecordVo> outrerecordVos = this.rerecordService.queryAll();
        return R.ok().put("data",outrerecordVos);
    }


    @ApiOperation(value="门诊充值记录搜索接口",notes="用于点击搜索门诊充值记录时",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊充值记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/rerecord/selectOutpatient")
    public R selectOutpatient(@ApiParam(name="begintime,endtime,namecard",value = "时间,病人/就诊卡号--用于搜索门诊充值记录",required = true)@RequestBody OutexvalueVo outexvalueVo){

        List<OutrerecordVo> outrerecordVos = this.rerecordService.selectAll(outexvalueVo.getBegintime(),outexvalueVo.getEndtime(),outexvalueVo.getNamecard());
        return R.ok().put("data",outrerecordVos);
    }

    @ApiOperation(value="门诊充值记录操作接口",notes="用于点击操作门诊充值记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊充值记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/rerecord/oderDetails")
    public R oderDetails(@ApiParam(name="order_num,medcard",value = "订单号,就诊卡号--用于搜索门诊充值记录",required = true)@RequestBody DovalueVo dovalueVo){

        //查询订单详情中的患者信息
        List<PatientmsgVo> patientmsgVo = this.rerecordService.queryAllpmsg(dovalueVo.getMedcard());
        List<OrderremsgVo> orderexmsgVos = this.rerecordService.queryAllomsg(dovalueVo.getOrder_num());

        Map map = new HashMap();

        map.put("patientmsg",patientmsgVo);
        map.put("ordermsg",orderexmsgVos);
        return R.ok().put("data",map);
    }

    @ApiOperation(value="门诊充值记录订单备注接口",notes="用于点击保存订单备注",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊充值记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/rerecord/updateOrderremark")
    public R updateOrderremark(@ApiParam(name="ordernum,remark",value = "订单号，备注信息--用于门诊充值记录的订单备注",required = true)@RequestBody OrderremsgVo orderremsgVo){
        this.rerecordService.updateRemark(orderremsgVo.getOrder_num(),orderremsgVo.getRemark());
        List<OrderremsgVo> orderremsgVos = this.rerecordService.queryAllomsg(orderremsgVo.getOrder_num());
        return R.ok().put("data",orderremsgVos);
    }

    //住院充值记录————————————————————————————————————————————————————————————————————————————————————————————————————



    @ApiOperation(value="住院充值记录渲染接口",notes="用于点击住院充值记录时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院充值记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/rerecord/queryHospitalization")
    public R queryHospitalization(){
        List<HosrerecordVo> hosrerecordVos = this.rerecordService.queryAllHos();
        return R.ok().put("data",hosrerecordVos);
    }

    @ApiOperation(value="住院充值记录搜索接口",notes="用于点击搜索住院充值记录时",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院充值记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/rerecord/selectHospitalization")
    public R selectHospitalization(@ApiParam(name="begintime,endtime,namehospitalcard",value = "时间,病人/住院号/就诊卡号--用于搜索住院消费记录",required = true)@RequestBody HosexvalueVo hosexvalueVo){
        List<HosrerecordVo> hosrerecordVos = this.rerecordService.selectAllHos(hosexvalueVo.getBegintime(),hosexvalueVo.getEndtime(),hosexvalueVo.getNamehospital());
        return R.ok().put("data",hosrerecordVos);
    }

    @ApiOperation(value="住院充值记录操作接口",notes="用于点击操作住院充值记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院充值记录的详细信息，其中住院信息不用做",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/rerecord/oderDetails1")
    public R oderDetails1(@ApiParam(name="order_num,medcard",value = "订单号,就诊卡号--用于搜索住院充值记录",required = true)@RequestBody DovalueVo dovalueVo){

        //查询订单详情中的患者信息
        List<PatientmsgVo> patientmsgVos = this.rerecordService.queryAllpmsg(dovalueVo.getMedcard());
        List<OrderremsgVo> orderremsgVos = this.rerecordService.queryAllomsg(dovalueVo.getOrder_num());

        Map map = new HashMap();
        map.put("patientmsg",patientmsgVos);
        map.put("ordermsg",orderremsgVos);

        return R.ok().put("data",map);
    }




    @ApiOperation(value="住院充值记录订单备注接口",notes="用于点击保存订单备注",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院充值记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:update")
    @PostMapping("/rerecord/updateHosremark")
    public R updateHosremark(@ApiParam(name="ordernum,remark",value = "订单号，备注信息--用于住院充值记录的订单备注",required = true)@RequestBody OrderremsgVo orderremsgVo){

        this.rerecordService.updateRemark(orderremsgVo.getOrder_num(),orderremsgVo.getRemark());
        List<OrderremsgVo> orderexmsgVos = this.rerecordService.queryAllomsg(orderremsgVo.getOrder_num());
        return R.ok().put("data",orderexmsgVos);
    }




    @ApiOperation(value="查询余额接口",notes="用于查询余额",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回余额详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/rerecord/selectBalance")
    public R selectBalance(@ApiParam(name="id",value = "当前用户的id--用于查询余额",required = true)@RequestBody User user){

        Integer balance = this.rerecordService.selectBalance(user.getId());
        return R.ok().put("data",balance);
    }

    @ApiOperation(value="充值接口",notes="用于充值",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回余额详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:add")
    @PostMapping("/rerecord/rechargeBalance")
    public R rechargeBalance(@ApiParam(name="id,money",value = "当前用户的id,充值的金额--用于充值",required = true)@RequestBody RechargeVo rechargeVo){

        this.rerecordService.rechargeBalance(rechargeVo.getId(),rechargeVo.getMoney());
        Integer newbalance = this.rerecordService.selectBalance(rechargeVo.getId());
        return R.ok().put("data",newbalance);
    }

}
